package com.tool.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author 酒徒
 * @Version 1.0
 * @data 2024/1/25 12:02
 * filter 启动类中加入@ServletComponentScan
 */
//@WebFilter(urlPatterns = "/*") //需要过滤的地址 /*:所有地址
public class CheckFilter implements Filter {

    @Override //初始化方法，只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init 初始化方法执行了");
    }


    @Override //拦截到请求之后调用，调用多次
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("拦截到了请求");
        //放行
        chain.doFilter(request, response);
    }


    @Override //销毁方法，只调用一次
    public void destroy() {
        System.out.println("destroy 销毁方法执行了");
    }
}
